package GUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;

import com.sun.tools.javac.Main;
import 数据库和网络.myDatebase;
import 试题和试卷.definitionQuestion;
import 试题和试卷.selectionQuestion;
import 试题和试卷.subjectiveQuestion;
import 试题和试卷.fillingblankQuestion;
import 试题和试卷.question;

public class organizePaperWindow extends JFrame {

    public static JPanel mainPanel;
    public static ArrayList<selectionQuestion>selectionQuestions;
    public static ArrayList<definitionQuestion>definitionQuestions;
    public static ArrayList<subjectiveQuestion>subjectiveQuestions;
    public static ArrayList<fillingblankQuestion>fillingblankQuestions;
    public static ArrayList<question>questions;
    public JButton detailButton,finishButton,confirmButton;
    public JLabel timeLabel,numLabel, nameLabel;
    static organizePaperWindow randomOrganize;
    public static double max,min;
    JTextArea time,number,name;
    String PAPERNAME,TIME;


    public static void main(String[] args) {
        new organizePaperWindow();
    }

    public organizePaperWindow(){
        mainPanel = new JPanel();
        mainPanel.setLayout(null);
        selectionQuestions= new ArrayList<>();
        definitionQuestions= new ArrayList<>();
        subjectiveQuestions= new ArrayList<>();
        fillingblankQuestions= new ArrayList<>();
        questions=new ArrayList<>();
        int selectionNum=0,definitionNum = 0,fillingBlankNum= 0,subjectiveNum= 0;

        JLabel selectionLabel = new JLabel("选择题");
        JLabel definitionLabel = new JLabel("判断题");
        JLabel fillingBlankLabel = new JLabel("填空题");
        JLabel subjectiveLabel = new JLabel("简答题");
        JLabel selectionNumLabel = new JLabel("已添加"+selectionNum+"道选择题");
        JLabel definitionNumLabel = new JLabel("已添加"+definitionNum+"道判断题");
        JLabel fillingBlankNumLabel = new JLabel("已添加"+fillingBlankNum+"道填空题");
        JLabel subjectiveNumLabel = new JLabel("已添加"+subjectiveNum+"道简答题");
        JButton addSelection = new JButton("添加试题");
        JButton addDefinition = new JButton("添加试题");
        JButton addFillingBlank = new JButton("添加试题");
        JButton addSubjective = new JButton("添加试题");
        detailButton = new JButton("查看试题");
        finishButton = new JButton("完成组卷");
        confirmButton=new JButton("确认");

        nameLabel= new JLabel("试卷名称：");
        name=new JTextArea(1,10);
        timeLabel= new JLabel("考试时间：");
        time=new JTextArea(1,3);
        numLabel= new JLabel("题目数量：");
        number=new JTextArea(1,3);


        addSelection.setBackground(Color.lightGray);
        //addSelection.addActionListener(new addSubjectiveWindow.addListener());
        addDefinition.setBackground(Color.lightGray);
        //addDefinition.addActionListener(new addSubjectiveWindow.backListener());
        addFillingBlank.setBackground(Color.lightGray);
        //addFillingBlank.addActionListener(new addSubjectiveWindow.addListener());
        addSubjective.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        detailButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        finishButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        confirmButton.setBackground(Color.lightGray);

        selectionLabel.setBounds(40,30,50,30);
        definitionLabel.setBounds(40,90,50,30);
        fillingBlankLabel.setBounds(40,150,50,30);
        subjectiveLabel.setBounds(40,210,50,30);
        addSelection.setBounds(100,30,100,30);
        addDefinition.setBounds(100,90,100,30);
        addFillingBlank.setBounds(100,150,100,30);
        addSubjective.setBounds(100,210,100,30);
        selectionNumLabel.setBounds(220,30,120,30);
        definitionNumLabel.setBounds(220,90,120,30);
        fillingBlankNumLabel.setBounds(220,150,120,30);
        subjectiveNumLabel.setBounds(220,210,120,30);
        detailButton.setBounds(60,290,90,30);
        finishButton.setBounds(210,290,90,30);
        confirmButton.setBounds(210,290,90,30);

        addSelection.addActionListener(new addSelectionListener());
        addDefinition.addActionListener(new addDefinitionListener());
        addFillingBlank.addActionListener(new addFillingBlankListener());
        addSubjective.addActionListener(new addSubjectiveListener());
        detailButton.addActionListener(new checkListener());



        mainPanel.add(selectionLabel);
        mainPanel.add(definitionLabel);
        mainPanel.add(fillingBlankLabel);
        mainPanel.add(subjectiveLabel);
        mainPanel.add(addSelection);
        mainPanel.add(addDefinition);
        mainPanel.add(addFillingBlank);
        mainPanel.add(addSubjective);
        mainPanel.add(selectionNumLabel);
        mainPanel.add(definitionNumLabel);
        mainPanel.add(fillingBlankNumLabel);
        mainPanel.add(subjectiveNumLabel);
        mainPanel.add(detailButton);
        mainPanel.add(finishButton);





        this.setTitle("组卷");
        this.setContentPane(mainPanel);
        this.setSize(370,400);
        mainPanel.setSize(this.getSize());
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        //this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public organizePaperWindow(ArrayList SELECTION,ArrayList DEFINITION,ArrayList FILLINGBLANK,ArrayList SUBJECTIVE,String PAPERNAME,String TIME){
        mainPanel = new JPanel();
        mainPanel.setLayout(null);
        selectionQuestions= new ArrayList<>();
        definitionQuestions= new ArrayList<>();
        subjectiveQuestions= new ArrayList<>();
        fillingblankQuestions= new ArrayList<>();
        questions=new ArrayList<>();

        selectionQuestions=SELECTION;
        definitionQuestions=DEFINITION;
        fillingblankQuestions=FILLINGBLANK;
        subjectiveQuestions=SUBJECTIVE;
        questions.addAll(selectionQuestions);
        questions.addAll(definitionQuestions);
        questions.addAll(fillingblankQuestions);
        questions.addAll(subjectiveQuestions);
        this.PAPERNAME=PAPERNAME;
        this.TIME=TIME;


        int selectionNum=selectionQuestions.size(),definitionNum = definitionQuestions.size(),fillingBlankNum= fillingblankQuestions.size(),subjectiveNum= subjectiveQuestions.size();

        JLabel selectionLabel = new JLabel("选择题");
        JLabel definitionLabel = new JLabel("判断题");
        JLabel fillingBlankLabel = new JLabel("填空题");
        JLabel subjectiveLabel = new JLabel("简答题");
        JLabel selectionNumLabel = new JLabel("已添加"+selectionNum+"道选择题");
        JLabel definitionNumLabel = new JLabel("已添加"+definitionNum+"道判断题");
        JLabel fillingBlankNumLabel = new JLabel("已添加"+fillingBlankNum+"道填空题");
        JLabel subjectiveNumLabel = new JLabel("已添加"+subjectiveNum+"道简答题");
        JButton addSelection = new JButton("添加试题");
        JButton addDefinition = new JButton("添加试题");
        JButton addFillingBlank = new JButton("添加试题");
        JButton addSubjective = new JButton("添加试题");
        detailButton = new JButton("查看试题");
        finishButton = new JButton("完成组卷");
        confirmButton=new JButton("确认");

        nameLabel= new JLabel("试卷名称：");
        name=new JTextArea(1,10);
        timeLabel= new JLabel("考试时间：");
        time=new JTextArea(1,3);
        numLabel= new JLabel("题目数量：");
        number=new JTextArea(1,3);

        name.setText(PAPERNAME);
        time.setText(TIME);

        addSelection.setBackground(Color.lightGray);
        //addSelection.addActionListener(new addSubjectiveWindow.addListener());
        addDefinition.setBackground(Color.lightGray);
        //addDefinition.addActionListener(new addSubjectiveWindow.backListener());
        addFillingBlank.setBackground(Color.lightGray);
        //addFillingBlank.addActionListener(new addSubjectiveWindow.addListener());
        addSubjective.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        detailButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        finishButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        confirmButton.setBackground(Color.lightGray);

        selectionLabel.setBounds(40,30,50,30);
        definitionLabel.setBounds(40,90,50,30);
        fillingBlankLabel.setBounds(40,150,50,30);
        subjectiveLabel.setBounds(40,210,50,30);
        addSelection.setBounds(100,30,100,30);
        addDefinition.setBounds(100,90,100,30);
        addFillingBlank.setBounds(100,150,100,30);
        addSubjective.setBounds(100,210,100,30);
        selectionNumLabel.setBounds(220,30,120,30);
        definitionNumLabel.setBounds(220,90,120,30);
        fillingBlankNumLabel.setBounds(220,150,120,30);
        subjectiveNumLabel.setBounds(220,210,120,30);
        detailButton.setBounds(60,290,90,30);
        finishButton.setBounds(210,290,90,30);
        confirmButton.setBounds(210,290,90,30);

        addSelection.addActionListener(new addSelectionListener());
        addDefinition.addActionListener(new addDefinitionListener());
        addFillingBlank.addActionListener(new addFillingBlankListener());
        addSubjective.addActionListener(new addSubjectiveListener());
        detailButton.addActionListener(new checkListener());



        mainPanel.add(selectionLabel);
        mainPanel.add(definitionLabel);
        mainPanel.add(fillingBlankLabel);
        mainPanel.add(subjectiveLabel);
        mainPanel.add(addSelection);
        mainPanel.add(addDefinition);
        mainPanel.add(addFillingBlank);
        mainPanel.add(addSubjective);
        mainPanel.add(selectionNumLabel);
        mainPanel.add(definitionNumLabel);
        mainPanel.add(fillingBlankNumLabel);
        mainPanel.add(subjectiveNumLabel);
        mainPanel.add(detailButton);
        mainPanel.add(finishButton);





        this.setTitle("组卷");
        this.setContentPane(mainPanel);
        this.setSize(370,400);
        mainPanel.setSize(this.getSize());
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        //this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public organizePaperWindow( String type){
        mainPanel = new JPanel();
        mainPanel.setLayout(null);
        selectionQuestions= new ArrayList<>();
        definitionQuestions= new ArrayList<>();
        subjectiveQuestions= new ArrayList<>();
        fillingblankQuestions= new ArrayList<>();
        questions=new ArrayList<>();
        int selectionNum=0,definitionNum = 0,fillingBlankNum= 0,subjectiveNum= 0;

        JLabel selectionLabel = new JLabel("选择题");
        JLabel definitionLabel = new JLabel("判断题");
        JLabel fillingBlankLabel = new JLabel("填空题");
        JLabel subjectiveLabel = new JLabel("简答题");
        JLabel selectionNumLabel = new JLabel("已添加"+selectionNum+"道选择题");
        JLabel definitionNumLabel = new JLabel("已添加"+definitionNum+"道判断题");
        JLabel fillingBlankNumLabel = new JLabel("已添加"+fillingBlankNum+"道填空题");
        JLabel subjectiveNumLabel = new JLabel("已添加"+subjectiveNum+"道简答题");
        JButton addSelection = new JButton("添加试题");
        JButton addDefinition = new JButton("添加试题");
        JButton addFillingBlank = new JButton("添加试题");
        JButton addSubjective = new JButton("添加试题");
        detailButton = new JButton("查看试题");
        finishButton = new JButton("完成组卷");
        confirmButton=new JButton("确认");

        name.setText(PAPERNAME);
        time.setText(TIME);

        addSelection.setBackground(Color.lightGray);
        //addSelection.addActionListener(new addSubjectiveWindow.addListener());
        addDefinition.setBackground(Color.lightGray);
        //addDefinition.addActionListener(new addSubjectiveWindow.backListener());
        addFillingBlank.setBackground(Color.lightGray);
        //addFillingBlank.addActionListener(new addSubjectiveWindow.addListener());
        addSubjective.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        detailButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        finishButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        confirmButton.setBackground(Color.lightGray);

        selectionLabel.setBounds(40,30,50,30);
        definitionLabel.setBounds(40,90,50,30);
        fillingBlankLabel.setBounds(40,150,50,30);
        subjectiveLabel.setBounds(40,210,50,30);
        addSelection.setBounds(100,30,100,30);
        addDefinition.setBounds(100,90,100,30);
        addFillingBlank.setBounds(100,150,100,30);
        addSubjective.setBounds(100,210,100,30);
        selectionNumLabel.setBounds(220,30,120,30);
        definitionNumLabel.setBounds(220,90,120,30);
        fillingBlankNumLabel.setBounds(220,150,120,30);
        subjectiveNumLabel.setBounds(220,210,120,30);
        detailButton.setBounds(60,290,90,30);
        finishButton.setBounds(210,290,90,30);
        confirmButton.setBounds(210,290,90,30);

        addSelection.addActionListener(new addRandomSelectionListener());
        addDefinition.addActionListener(new addRandomDefinitionListener());
        addFillingBlank.addActionListener(new addRandomFillingBlankListener());
        addSubjective.addActionListener(new addRandomSubjectiveListener());
        detailButton.addActionListener(new checkListener());



        mainPanel.add(selectionLabel);
        mainPanel.add(definitionLabel);
        mainPanel.add(fillingBlankLabel);
        mainPanel.add(subjectiveLabel);
        mainPanel.add(addSelection);
        mainPanel.add(addDefinition);
        mainPanel.add(addFillingBlank);
        mainPanel.add(addSubjective);
        mainPanel.add(selectionNumLabel);
        mainPanel.add(definitionNumLabel);
        mainPanel.add(fillingBlankNumLabel);
        mainPanel.add(subjectiveNumLabel);
        mainPanel.add(detailButton);
        mainPanel.add(finishButton);





        this.setTitle("组卷");
        this.setContentPane(mainPanel);
        this.setSize(370,400);
        mainPanel.setSize(this.getSize());
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        //this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public organizePaperWindow( Double type){
        mainPanel = new JPanel();
        mainPanel.setLayout(null);
        int selectionNum,definitionNum,fillingBlankNum,subjectiveNum;
        selectionNum=selectionQuestions.size();
        definitionNum=definitionQuestions.size();
        fillingBlankNum=fillingblankQuestions.size();
        subjectiveNum=subjectiveQuestions.size();

        JLabel selectionLabel = new JLabel("选择题");
        JLabel definitionLabel = new JLabel("判断题");
        JLabel fillingBlankLabel = new JLabel("填空题");
        JLabel subjectiveLabel = new JLabel("简答题");
        JLabel selectionNumLabel = new JLabel("已添加"+selectionNum+"道选择题");
        JLabel definitionNumLabel = new JLabel("已添加"+definitionNum+"道判断题");
        JLabel fillingBlankNumLabel = new JLabel("已添加"+fillingBlankNum+"道填空题");
        JLabel subjectiveNumLabel = new JLabel("已添加"+subjectiveNum+"道简答题");
        JButton addSelection = new JButton("添加试题");
        JButton addDefinition = new JButton("添加试题");
        JButton addFillingBlank = new JButton("添加试题");
        JButton addSubjective = new JButton("添加试题");
        detailButton = new JButton("查看试题");
        finishButton = new JButton("完成组卷");
        confirmButton=new JButton("确认");

        timeLabel = new JLabel("时间(min)：");
        time = new JTextArea(1,5);


        name.setText(PAPERNAME);
        time.setText(TIME);

        addSelection.setBackground(Color.lightGray);
        //addSelection.addActionListener(new addSubjectiveWindow.addListener());
        addDefinition.setBackground(Color.lightGray);
        //addDefinition.addActionListener(new addSubjectiveWindow.backListener());
        addFillingBlank.setBackground(Color.lightGray);
        //addFillingBlank.addActionListener(new addSubjectiveWindow.addListener());
        addSubjective.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        detailButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        finishButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        confirmButton.setBackground(Color.lightGray);

        selectionLabel.setBounds(40,30,50,30);
        definitionLabel.setBounds(40,90,50,30);
        fillingBlankLabel.setBounds(40,150,50,30);
        subjectiveLabel.setBounds(40,210,50,30);
        addSelection.setBounds(100,30,100,30);
        addDefinition.setBounds(100,90,100,30);
        addFillingBlank.setBounds(100,150,100,30);
        addSubjective.setBounds(100,210,100,30);
        selectionNumLabel.setBounds(220,30,120,30);
        definitionNumLabel.setBounds(220,90,120,30);
        fillingBlankNumLabel.setBounds(220,150,120,30);
        subjectiveNumLabel.setBounds(220,210,120,30);
        detailButton.setBounds(60,290,90,30);
        finishButton.setBounds(210,290,90,30);
        confirmButton.setBounds(210,290,90,30);
        nameLabel.setBounds(40,50,70,20);
        name.setBounds(110,50,100,30);
        timeLabel.setBounds(20,260,70,20);
        time.setBounds(100,260,200,30);


        addSelection.addActionListener(new addRandomSelectionListener());
        addDefinition.addActionListener(new addRandomDefinitionListener());
        addFillingBlank.addActionListener(new addRandomFillingBlankListener());
        addSubjective.addActionListener(new addRandomSubjectiveListener());
        detailButton.addActionListener(new checkListener());

        /*if(selectionNum>0){
            addSelection.setEnabled(false);
        }
        if(definitionNum>0){
            addDefinition.setEnabled(false);
        }
        if(fillingBlankNum>0){
            addFillingBlank.setEnabled(false);
        }
        if(subjectiveNum>0){
            addSubjective.setEnabled(false);
        }*/

        mainPanel.add(selectionLabel);
        mainPanel.add(definitionLabel);
        mainPanel.add(fillingBlankLabel);
        mainPanel.add(subjectiveLabel);
        mainPanel.add(addSelection);
        mainPanel.add(addDefinition);
        mainPanel.add(addFillingBlank);
        mainPanel.add(addSubjective);
        mainPanel.add(selectionNumLabel);
        mainPanel.add(definitionNumLabel);
        mainPanel.add(fillingBlankNumLabel);
        mainPanel.add(subjectiveNumLabel);
        mainPanel.add(detailButton);
        mainPanel.add(finishButton);





        this.setTitle("组卷");
        this.setContentPane(mainPanel);
        this.setSize(370,400);
        if(!addSelection.isEnabled()&&!addDefinition.isEnabled()&&!addFillingBlank.isEnabled()&&!addSubjective.isEnabled()){
            mainPanel.add(timeLabel);
            mainPanel.add(time);
            mainPanel.add(nameLabel);
            mainPanel.add(name);
            detailButton.setBounds(60,330,90,30);
            finishButton.setBounds(210,330,90,30);
            this.setSize(370,540);
        }
        mainPanel.setSize(this.getSize());
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        //this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public organizePaperWindow(int type){
        mainPanel = new JPanel();
        mainPanel.setLayout(null);
        int selectionNum,definitionNum,fillingBlankNum,subjectiveNum;
        selectionNum=selectionQuestions.size();
        definitionNum=definitionQuestions.size();
        fillingBlankNum=fillingblankQuestions.size();
        subjectiveNum=subjectiveQuestions.size();

        JLabel selectionLabel = new JLabel("选择题");
        JLabel definitionLabel = new JLabel("判断题");
        JLabel fillingBlankLabel = new JLabel("填空题");
        JLabel subjectiveLabel = new JLabel("简答题");
        JLabel selectionNumLabel = new JLabel("已添加"+selectionNum+"道选择题");
        JLabel definitionNumLabel = new JLabel("已添加"+definitionNum+"道判断题");
        JLabel fillingBlankNumLabel = new JLabel("已添加"+fillingBlankNum+"道填空题");
        JLabel subjectiveNumLabel = new JLabel("已添加"+subjectiveNum+"道简答题");
        JButton addSelection = new JButton("添加试题");
        JButton addDefinition = new JButton("添加试题");
        JButton addFillingBlank = new JButton("添加试题");
        JButton addSubjective = new JButton("添加试题");
        /*JButton*/ detailButton = new JButton("查看试题");
        /*JButton */finishButton = new JButton("完成组卷");
        confirmButton=new JButton("确认");


        nameLabel= new JLabel("试卷名称：");
        name=new JTextArea(1,10);
        timeLabel= new JLabel("考试时间：");
        time=new JTextArea(1,3);

        name.setText(PAPERNAME);
        time.setText(TIME);


        addSelection.setBackground(Color.lightGray);
        //addSelection.addActionListener(new addSubjectiveWindow.addListener());
        addDefinition.setBackground(Color.lightGray);
        //addDefinition.addActionListener(new addSubjectiveWindow.backListener());
        addFillingBlank.setBackground(Color.lightGray);
        //addFillingBlank.addActionListener(new addSubjectiveWindow.addListener());
        addSubjective.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        detailButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        finishButton.setBackground(Color.lightGray);
        //addSubjective.addActionListener(new addSubjectiveWindow.backListener());
        confirmButton.setBackground(Color.lightGray);

        selectionLabel.setBounds(40,30,50,30);
        definitionLabel.setBounds(40,90,50,30);
        fillingBlankLabel.setBounds(40,150,50,30);
        subjectiveLabel.setBounds(40,210,50,30);
        addSelection.setBounds(100,30,100,30);
        addDefinition.setBounds(100,90,100,30);
        addFillingBlank.setBounds(100,150,100,30);
        addSubjective.setBounds(100,210,100,30);
        selectionNumLabel.setBounds(220,30,120,30);
        definitionNumLabel.setBounds(220,90,120,30);
        fillingBlankNumLabel.setBounds(220,150,120,30);
        subjectiveNumLabel.setBounds(220,210,120,30);
        detailButton.setBounds(60,300,90,30);
        finishButton.setBounds(210,300,90,30);
        confirmButton.setBounds(210,300,90,30);
        nameLabel.setBounds(20,260,70,20);
        name.setBounds(100,260,200,30);
        timeLabel.setBounds(20,300,70,20);
        time.setBounds(100,300,200,30);


        addSelection.addActionListener(new addSelectionListener());
        addDefinition.addActionListener(new addDefinitionListener());
        addFillingBlank.addActionListener(new addFillingBlankListener());
        addSubjective.addActionListener(new addSubjectiveListener());
        detailButton.addActionListener(new checkListener());
        finishButton.addActionListener(new finishListener());

        /*if(selectionNum>0){
            addSelection.setEnabled(false);
        }
        if(definitionNum>0){
            addDefinition.setEnabled(false);
        }
        if(fillingBlankNum>0){
            addFillingBlank.setEnabled(false);
        }
        if(subjectiveNum>0){
            addSubjective.setEnabled(false);
        }*/


        mainPanel.add(selectionLabel);
        mainPanel.add(definitionLabel);
        mainPanel.add(fillingBlankLabel);
        mainPanel.add(subjectiveLabel);
        mainPanel.add(addSelection);
        mainPanel.add(addDefinition);
        mainPanel.add(addFillingBlank);
        mainPanel.add(addSubjective);
        mainPanel.add(selectionNumLabel);
        mainPanel.add(definitionNumLabel);
        mainPanel.add(fillingBlankNumLabel);
        mainPanel.add(subjectiveNumLabel);
        mainPanel.add(detailButton);
        mainPanel.add(finishButton);




        this.setTitle("组卷");
        this.setContentPane(mainPanel);
        this.setSize(370,400);
            mainPanel.add(timeLabel);
            mainPanel.add(time);
            mainPanel.add(nameLabel);
            mainPanel.add(name);
            detailButton.setBounds(60,370,90,30);
            finishButton.setBounds(210,370,90,30);
            this.setSize(370,480);
        mainPanel.setSize(this.getSize());
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        //this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public class addSelectionListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
           new questionAddWindow(1);
           organizePaperWindow.this.dispose();

        }
    }
    public class addDefinitionListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            new questionAddWindow(2);
            organizePaperWindow.this.dispose();

        }
    }
    public class addFillingBlankListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            new questionAddWindow(3);
            organizePaperWindow.this.dispose();

        }
    }
    public class addSubjectiveListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            new questionAddWindow(4);
            organizePaperWindow.this.dispose();

        }
    }
    public class addRandomSelectionListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            new questionAddWindow(5);
            organizePaperWindow.this.dispose();

        }
    }
    public class addRandomDefinitionListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            new questionAddWindow(6);
            organizePaperWindow.this.dispose();

        }
    }
    public class addRandomFillingBlankListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            new questionAddWindow(7);
            organizePaperWindow.this.dispose();

        }
    }
    public class addRandomSubjectiveListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            new questionAddWindow(8);
            organizePaperWindow.this.dispose();

        }
    }
    public class finishListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){

            if(timeLabel.getText()!=null&&name.getText()!=null){
                int min=Integer.parseInt(time.getText());
                String nam=name.getText();
                ArrayList<String> t=new ArrayList<>();
                //要在papercollection中创建一个试卷表，在对应class中创建条目，创建result_record中一张表,其中有学生
                //时间，各个题目分数，current answer，properanswer
                myDatebase infoClass=new myDatebase("information_schema");
                myDatebase classFinder=new myDatebase("teacher");
                myDatebase resultCreator=new myDatebase("result_record");
                myDatebase paperUploader=new myDatebase("papercollection");
                ArrayList<String> classList=new ArrayList<>();
                ArrayList<String> realclasslist=new ArrayList<>();
                try {
                    String sql ="select * from INNODB_TABLES where NAME like '%papercollection%%class%'";
                    infoClass.statement.execute(sql);
                    infoClass.resultSet=infoClass.statement.executeQuery(sql);
                    ArrayList<String> NamList=new ArrayList<>();
                    while (infoClass.resultSet.next()){
                        String linshi=infoClass.resultSet.getString(2).substring(16);
                        classList.add(linshi);
                        System.out.println(linshi);
                    }
                    sql="select * from teacher.teacher where teacherID="+enterWindow.currentTeacher.getSchoolID()+"";
                    classFinder.statement.execute(sql);
                    classFinder.resultSet=classFinder.statement.executeQuery(sql);
                    while(classFinder.resultSet.next()){
                        Iterator<String> ite=classList.iterator();
                        while(ite.hasNext()){
                            String j=ite.next();
                            if(classFinder.resultSet.getString(j).equals("true")){
                                realclasslist.add(j);
                                System.out.println(j);
                            }
                        }
                    }

                    sql=String.format("create table %s (questionText longtext,questionName char(20)," +
                            "questionPattern char(20),questionDifficulties double,fullScore int,answer longtext)",nam);
                    paperUploader.statement.executeUpdate(sql);

                    Iterator<selectionQuestion> selIte=selectionQuestions.iterator();
                    while(selIte.hasNext()){
                        selectionQuestion st=selIte.next();
                        sql=String.format("insert into papercollection.%s (questiontext, questionname, questionpattern, questiondifficulties, fullscore, answer) " +
                                "values ('"+st.getText()+"','"+st.getTitle()+"','selection',"+st.getDifficulty()+","+st.getFullScore()+",'"+st.getAnswer()+"')",nam);
                        paperUploader.statement.execute(sql);
                    }

                    Iterator<definitionQuestion> defIte=definitionQuestions.iterator();
                    while(defIte.hasNext()){
                        definitionQuestion st=defIte.next();
                        sql=String.format("insert into papercollection.%s (questiontext, questionname, questionpattern, questiondifficulties, fullscore, answer) " +
                                "values ('"+st.getText()+"','"+st.getTitle()+"','definition',"+st.getDifficulty()+","+st.getFullScore()+",'"+st.getAnswer()+"')",nam);
                        paperUploader.statement.execute(sql);
                    }

                    Iterator<fillingblankQuestion> fillIte=fillingblankQuestions.iterator();
                    while(fillIte.hasNext()){
                        fillingblankQuestion st=fillIte.next();
                        sql=String.format("insert into papercollection.%s (questiontext, questionname, questionpattern, questiondifficulties, fullscore, answer) " +
                                "values ('"+st.getText()+"','"+st.getTitle()+"','fillingBlank',"+st.getDifficulty()+","+st.getFullScore()+",'"+st.getAnswer()+"')",nam);
                        paperUploader.statement.execute(sql);
                    }

                    Iterator<subjectiveQuestion> subIte=subjectiveQuestions.iterator();
                    while(subIte.hasNext()){
                        subjectiveQuestion st=subIte.next();
                        sql=String.format("insert into papercollection.%s (questiontext, questionname, questionpattern, questiondifficulties, fullscore, answer) " +
                                "values ('"+st.getText()+"','"+st.getTitle()+"','subjective',"+st.getDifficulty()+","+st.getFullScore()+",'"+st.getAnswer()+"')",nam);
                        paperUploader.statement.execute(sql);
                    }



                    Iterator<String> iet=realclasslist.iterator();
                    while(iet.hasNext()){
                        String rel=iet.next();
                        sql=String.format("insert into papercollection.%s (paperTitle, limitedTime) values " +
                                "('"+name.getText()+"',"+Integer.parseInt(time.getText())+")",rel);
                        paperUploader.statement.execute(sql);
                    }
                    //传到papercollection里每个class了

                    sql="create table "+nam+"(studentID char(20),remainTime int,fillingblank_score int,subjective_score int,definition_score int,selection_score int)";
                    resultCreator.statement.execute(sql);

                    Iterator<definitionQuestion> defIter=definitionQuestions.iterator();
                    while(defIter.hasNext()){
                        definitionQuestion currdef=defIter.next();
                        sql=String.format("alter table %s add column "+currdef.getTitle()+"_proper_answer longtext",nam);
                        resultCreator.statement.execute(sql);
                        sql=String.format("alter table %s add column "+currdef.getTitle()+"_current_answer longtext",nam);
                        resultCreator.statement.execute(sql);
                        //resultCreator.resultSet=resultCreator.statement.executeQuery(sql);
                    }

                    Iterator<selectionQuestion> selIter=selectionQuestions.iterator();
                    while(selIter.hasNext()){
                        selectionQuestion currsel=selIter.next();
                        sql=String.format("alter table %s add column "+currsel.getTitle()+"_proper_answer longtext",nam);
                        resultCreator.statement.execute(sql);
                        sql=String.format("alter table %s add column "+currsel.getTitle()+"_current_answer longtext",nam);
                        resultCreator.statement.execute(sql);
                    }
                    Iterator<fillingblankQuestion> fillIter=fillingblankQuestions.iterator();
                    while(fillIter.hasNext()){
                        fillingblankQuestion currfill=fillIter.next();
                        sql=String.format("alter table %s add column "+currfill.getTitle()+"_proper_answer longtext",nam);
                        resultCreator.statement.execute(sql);
                        sql=String.format("alter table %s add column "+currfill.getTitle()+"_current_answer longtext",nam);
                        resultCreator.statement.execute(sql);

                    }
                    Iterator<subjectiveQuestion> subIter=subjectiveQuestions.iterator();
                    while(subIter.hasNext()){
                        subjectiveQuestion currsub=subIter.next();
                        sql=String.format("alter table %s add column "+currsub.getTitle()+"_proper_answer longtext",nam);
                        resultCreator.statement.execute(sql);
                        sql=String.format("alter table %s add column "+currsub.getTitle()+"_current_answer longtext",nam);
                        resultCreator.statement.execute(sql);
                        //resultCreator.resultSet=resultCreator.statement.executeQuery(sql);
                    }
                    sql=String.format("alter table %s add column is_revised char(20)",nam);
                    resultCreator.statement.execute(sql);
                    sql=String.format("update result_record.%s set is_revised='no'",nam);
                    resultCreator.statement.execute(sql);


                    ArrayList<String> stuID=new ArrayList<>();

                    Iterator<String> clss=realclasslist.iterator();
                    myDatebase stusel=new myDatebase("student");
                    while(clss.hasNext()){
                        String cllaass=clss.next();
                        sql="select * from student.student where student.student.class='"+cllaass+"'";
                        stusel.statement.execute(sql);
                        stusel.resultSet=stusel.statement.executeQuery(sql);
                        while(stusel.resultSet.next()){
                            stuID.add(stusel.resultSet.getString(2));
                        }
                    }

                    Iterator<String> stuadd=stuID.iterator();
                    while(stuadd.hasNext()){
                        String a=stuadd.next();
                        sql=String.format("insert into result_record.%s (studentID, remainTime) values ('"+a+"',"+min*60+")",nam);
                        resultCreator.statement.execute(sql);
                    }

                    for(int i=0;i<questions.size();i++){
                        if(questions.get(i).getType().equals("selection")){
                        sql=String.format("update result_record.%s set %s_current_answer = 'a' ",nam,questions.get(i).getTitle());
                        resultCreator.statement.execute(sql);}
                        else if(questions.get(i).getType().equals("definition")){
                            sql=String.format("update result_record.%s set %s_current_answer = 'true' ",nam,questions.get(i).getTitle());
                            resultCreator.statement.execute(sql);
                        }else{
                            sql=String.format("update result_record.%s set %s_current_answer = '此处输入答案' ",nam,questions.get(i).getTitle());
                            resultCreator.statement.execute(sql);
                        }
                    }


                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
                organizePaperWindow.this.dispose();
                successfulLog.successful= new successfulLog("a");
                successfulLog.successful.successLab.setText("组卷成功！");
                successfulLog.successful.panel.updateUI();



            }

            //organizePaperWindow.this.dispose();
        }
    }
    public class checkListener implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e){
            new paperCheckingWindow();

        }
    }
}
